
<html>
<head>

<title>Discipline Analytic</title>
</head>
<body>


<%-- Import the java.sql package --%>
            <%@ page import="java.sql.*"%>
            <%-- -------- Open Connection Code -------- --%>
            <%
            
            Connection conn = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            Statement stmt =null;
            
           try{
                // Registering Postgresql JDBC driver with the DriverManager
                Class.forName("org.postgresql.Driver");

                // Open a connection to the database using DriverManager
                conn = DriverManager.getConnection(
                		"jdbc:postgresql://localhost:5433/GradApp?" +
                        "user=postgres&password=20880130");
                
      %>
      
      <table>
      <%
      stmt = conn.createStatement();
      String QuaryString = "SELECT Discipline.name, count(*),Discipline.id "+
                          "FROM  Degrees,Discipline " +
                          "WHERE Degrees.discipline=Discipline.id  "+
                          "GROUP BY Discipline.name,Discipline.id";
      rs = stmt.executeQuery(QuaryString);
      
    	  %>
    	  <tr>
    	  <th> Discipline</th>
    	  <th> Number of Applications</th>
    	  </tr>
    	 <% while (rs.next()){ %>
    	  <tr>
    	  <td> <%=rs.getString(1) %></td>
    	  <td> <a href="Applications.jsp?DiscApp=<%=rs.getInt(3)%>"><%=rs.getInt(2)%></a></td> 
    	    
    	  </tr>
      <%   
      }
      %>	    
            
   
      </table>
      
      
      
      
                
      <%        
           } catch (SQLException e) {

               // Wrap the SQL exception in a runtime exception to propagate
               // it upwards
               throw new RuntimeException(e);
           }
           finally {
               // Release resources in a finally block in reverse-order of
               // their creation

               if (rs != null) {
                   try {
                       rs.close();
                   } catch (SQLException e) { } // Ignore
                   rs = null;
               }
               if (pstmt != null) {
                   try {
                       pstmt.close();
                   } catch (SQLException e) { } // Ignore
                   pstmt = null;
               }
               if (conn != null) {
                   try {
                       conn.close();
                   } catch (SQLException e) { } // Ignore
                   conn = null;
               }
           } 
   %>             


</body>
</html>